<?php
/**
 * createNewTeacherNo()
 *
 * @return
 */
function createNewTeacherNo()
{
    static $counter = 0;
    $counter++;
    $Year = date("Y");
    $last_id = (int)getLastTeacherId();
    if (false == $last_id) {
        $new_no = (int)($Year) * 100000 + $counter;
    } else {
        $new_no = (int)($Year) * 100000 + $last_id + $counter;
    }
    return "T" . $new_no;
}

/**
 * getLastTeacherId()
 *
 * @return
 */
function getLastTeacherId()
{
    $sql = "SELECT MAX(teacher_id) FROM " . DB_PREFIX . "teacher";
    $result = zeus_sql_query($sql, false);
    if (null != $result) {
        return $result['MAX(teacher_id)'];
    } else {
        return false;
    }
}
/**
 * getTheTeacherName()
 *
 * @param string $sTeacherNo
 * @return
 */
function getTheTeacherName($sTeacherNo = "")
{
    $sql = "SELECT teacher_name FROM " . DB_PREFIX . "teacher WHERE teacher_no='" . $sTeacherNo . "'";
    $result = zeus_sql_query($sql, false);
    if (null != $result) {
        return $result['teacher_name'];
    } else {
        return false;
    }
}
/**
 * getTheTeacherDetail()
 *
 * @param string $sTeacherNo
 * @return
 */
function getTheTeacherDetail($sTeacherNo = "", $sOption = "")
{
    $sql = "SELECT detail FROM " . DB_PREFIX . "rel_teacher_info WHERE teacher_no='" . $sTeacherNo . "'";
    $result = zeus_sql_query($sql, false);
    if (null != $result) {
        $detail = unserialize($result['detail']);
        if ("" != $sOption && null != $detail) {
            return $detail[$sOption];
        } else {
            return null;
        }
    } else {
        return false;
    }
}
/**
 * getTheTeacherPrevClasses()
 *
 * @param string $sTeacherNo
 * @return
 */
function getTheTeacherClasses($sTeacherNo = "")
{
    $sql = "SELECT myclasses FROM " . DB_PREFIX . "rel_teacher_info WHERE teacher_no='" . $sTeacherNo . "'";
    $result = zeus_sql_query($sql, false);
    if (null != $result) {
        return unserialize($result['myclasses']);
    } else {
        return false;
    }
}
/**
 * getMasterCurrentClassId()
 *
 * @param string $sTeacherNo
 * @return
 */
function getMasterClassId($sTeacherNo = "")
{
    $sql = "SELECT myclasses FROM " . DB_PREFIX . "rel_teacher_info WHERE teacher_no='" . $sTeacherNo . "'";
    $result = zeus_sql_query($sql, false);
    if (null != $result) {
        $myclasses = unserialize($result['myclasses']);
        $currentYear = date("Y");
        return $myclasses[$currentYear];
    } else {
        return false;
    }
}
/**
 * addTheTeacherDetail()
 *
 * @param string $sTeacherNo
 * @param string $sOption
 * @param string $sValue
 * @return
 */
function addTheTeacherDetail($sTeacherNo = "", $sOption = "", $sValue = "")
{
    $sql = "SELECT detail FROM " . DB_PREFIX . "rel_teacher_info WHERE teacher_no='" . $sTeacherNo . "'";
    $result = zeus_sql_query($sql, false);
    if (null != $result) {
        $detail = unserialize($result['detail']);
        if ("" != $sOption && "" != $sValue) {
            $detail[$sOption] = $sValue;
            $newDetail = serialize($detail);
            $sql = "UPDATE " . DB_PREFIX . "rel_teacher_info SET detail='" . $newDetail . "'";
            if (zeus_sql_exec($sql, false)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}

?>